package wechat.rcv;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import wechat.rcv.cosuming.AuthConsuming;

@RestController
@RequestMapping(value="/auth")
@ResponseBody
@Transactional
public class AuthFrontController {
	final static Logger logger = Logger.getLogger(AuthFrontController.class.getName());
	
	@Autowired
	AuthConsuming  authConsuming;
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView ServiceAppUrlValidation(@RequestParam(value="code")String code, @RequestParam(value="state")String state) {
		logger.info("=========================>auth enter");
		
		
		
		String url = authConsuming.getRedirectUrl(code, state);
		logger.info("==================> auth url: " + url);
		
		return new ModelAndView(new RedirectView(url));
	}
}
